
$(function () {

	document.documentElement.style.fontSize = window.innerWidth/3.75 + 'px';
	


  //AX7 2.0L自动智逸型
  var data1 = {
    bannerUrl: "img/dongfeng_banner.jpg",
    carStyle: "AX7&nbsp;2.0L自动智逸型",
    price: "129700元",
    nameRent: "租金",
    rent: "3734元/月",
    detailUrl: "img/AX7 2.0L_peizhi.png"
  };
  //AX7 1.4T手动智悦型
  var data2 = {
    bannerUrl: "img/dongfeng_banner.jpg",
    carStyle: "AX7&nbsp;1.4T手动智悦型",
    price: "109700元",
    nameRent: "租金",
    rent: "3117元/月",
    detailUrl: "img/AX7 1.4T_peizhi.png"
  };
  //雅阁精英型
  var data3 = {
    bannerUrl: "img/yage_banner.jpg",
    carStyle: "2.0精英版",
    price: "189,800元",
    nameRent: "日租金",
    rent: "118元起",
    detailUrl: "img/yagejy_peizhi.jpg"
  };
  //雅阁舒适型
  var data4 = {
    bannerUrl: "img/yage_banner.jpg",
    carStyle: "2.0舒适版",
    price: "179,800元",
    nameRent: "日租金",
    rent: "100元起",
    detailUrl: "img/yagess_peizhi.jpg"
  };

  //获取模板
  var tpl = document.getElementById("tpl").innerHTML;

  //存放post的数据
  var data0 = {};
  data0.userId = getQueryStr("userId");
  data0.carId = getQueryStr("carId");

  var identifyId = getQueryStr("identifyId");
  
  //根据carId解析成不同的HTML
  switch(parseInt(data0.carId)){
    case 1:
      var html = juicer(tpl,data1);
      $("body").html(html);
      judgeOrder();
      break;
    case 2:
      var html = juicer(tpl,data2);
      $("body").html(html);
      judgeOrder();
      break;
    case 3:
      var html = juicer(tpl,data3);
      $("body").html(html);
      $(".delete").remove();
      judgeOrder();
      break;
    case 4:
      var html = juicer(tpl,data4);
      $("body").html(html);
      $(".delete").remove();
      judgeOrder();
      break;
  }

	function judgeOrder (){
		$.ajax({
      type: "post",
      url: "/dingding-web/rentSaleCarActiceAction!getRentSaleOrderStatus.action",
      dataType: "jsonp",
      async: false,
      jsonp: "callback",
      jsonpCallback: "success_jsop",
      data: {
      	userId: data0.userId
      },
      success: function(data){
				if(data.code == "201"){
					$(".footer-container button").text("查看预约订单").css({"background-color":"#FF4B4A"});
					$(".footer-container button").on("click",function(){
						window.location.href = "success_detail.html?"+
																		"userId="+data0.userId+"&carType="+data.responseBody.carType+"&city="+data.responseBody.city+
																		"&orderCreateTime="+data.responseBody.orderCreateTime+
																		"&orderStatus="+data.responseBody.orderStatus+"&identifyId="+identifyId+"&cityNo="+getQueryStr("cityNo");
					});
					$(".p-container p:eq(1)").text("您当前预约城市");
					$(".btn-background button").each(function(){
						if($(this).text() == data.responseBody.city){
							$(this).css({"background-color":"#FF4B4A","color":"#FFF"});
						}
					});
				}
				if(data.code == "200"){
					if(data0.carId == "1" || data0.carId == "2"){
						dfBtn();
					}
					if(data0.carId == "3" || data0.carId == "4"){
						ygBtn();
					}
					yuYue();
				}
      }
    });
	}

  /*页面滚动时设置body一个底填充*/
  $(window).scroll(function(){
    $(".spec-body").css({paddingBottom: "0.6rem"});
  });

  /*用户只有在选择城市的时候方可点击预约，点击城市获取对应的城市id*/
  function dfBtn(){
    $(".footer-container button").attr("disabled", true);
    $(".btn-background button").on("click",function(){
      data0.cityId = $(this).attr("data-cityId");
      $(".footer-container button").removeAttr("disabled").css({"background-color":"#FF4B4A"});
      $(".btn-background button").removeClass("active");
      $(this).addClass("active");
    });
  }
  function ygBtn(){
    $(".btn-background button").addClass("active");
    $(".footer-container button").removeAttr("disabled").css({"background-color":"#FF4B4A"});
    data0.cityId = $(".btn-background button").attr("data-cityId");
  }
  /*点击预约加载请求*/
  function yuYue(){
  	$(".footer-container button").on("click",function(){
    $.ajax({
      type: "post",
      url: "/dingding-web/rentSaleCarActiceAction!placeRentSaleOrder.action",
      dataType: "jsonp",
      async: false,
      jsonp: "callback",
      jsonpCallback: "success_jsop",
      data: data0,
      success: function(data){
        if(data.responseBody == "您已预约成功"){
          window.location.href = "success.html?userId="+data0.userId+"&carId="+data0.carId+"&identifyId="+identifyId+"&cityNo="+getQueryStr("cityNo");
        }else{
          swal({
            title: data.responseBody,
            type: "warning",
            confirmButtonColor: "#DD6B55",
            confirmButtonText: "确定",
          });
        }
      }
    });
  });
  };
  
  if(identifyId != "999"){
	  $(".close-icon").remove();
  }
  
  $(".close-icon").on("click",function(){
      window.history.back();
    })
  

});